package com.it.jzs.controller;

import com.it.jzs.service.CommentService;
import com.it.jzs.service.LinkCommentService;
import com.it.jzs.vo.Result;
import com.it.jzs.vo.params.CommentParams;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("linkcomment")
@CrossOrigin
public class LinkCommentController {

    @Resource
    private LinkCommentService linkCommentService;

    @Resource
    private CommentService commentService;

    @PostMapping("")  // 插入一条评论
    public Result<Object> insert(@RequestBody CommentParams commentParams) {
        System.out.println("commentParams = " + commentParams);
//        Result<Object> result = commentService.insert(commentParams);
        return Result.success(null, "测试评论");
    }

    @GetMapping("/user/{id}")  // 通过 评论id获取用户的id，返回前端给二级评论id设置父级
    public Result<Object> selectUserId(@PathVariable("id") Integer id) {
        Result<Object> result = commentService.selectUserIdByCommentId(id);


        return result;
    }

    @GetMapping("{id}")
    public Result<Object> selectAll(@PathVariable("id") Integer id) {  // 根据博客Id查询对应的评论
        System.out.println("id = " + id);
        Result<Object> result = commentService.selectAll(id);
        return result;
    }

    @GetMapping("/avatar/{id}")   // 获取用户的头像
    public Result<Object> selectUserAvatar(@PathVariable("id") Integer id) {
//        System.out.println("id = " + id);
        Result<Object> result = commentService.selectUserAvatar(id);
        return result;


    }

    @GetMapping("/count/{id}") // 根据博客id获取评论总数
    public Result<Object> selectCount(@PathVariable("id") Integer id) {
//        System.out.println("id = " + id);
        Result<Object> result = commentService.selectCount(id);
        return result;
//        return Result.success(null, "2");
    }


}
